import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';

// 静态路由配置 - tenant-app 的所有页面路由（使用完整路径，避免与其他微应用冲突）
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/tenant/user',
  },
  {
    path: '/tenant',
    component: () => import('@/layout/index.vue'),
    redirect: '/tenant/user',
    children: [
      {
        path: '/tenant/user',
        name: 'TenantList',
        component: () => import('@/views/tenantUser/index.vue'),
        meta: {
          title: '租户管理',
        },
      },
      {
        path: '/tenant/tenantPackage',
        name: 'TenantPackage',
        component: () => import('@/views/tenantPackage/index.vue'),
        meta: {
          title: '租户套餐',
        },
      },
      {
        path: '/tenant/tenantApp',
        name: 'TenantApp',
        component: () => import('@/views/tenantApp/index.vue'),
        meta: {
          title: '租户应用',
        },
      },
    ]
  },
  {
    path: '/tenant/error/404',
    name: 'NotFound',
    component: () => import('@/views/error/404.vue'),
    meta: {
      title: '404',
    },
  },
  // 只处理租户相关的路径，其他路径让主应用处理
  {
    path: '/tenant/:pathMatch(.*)*',
    redirect: '/tenant/error/404',
  },
];

// 创建路由实例（使用根路径，路由定义已包含完整路径）
const router = createRouter({
  history: createWebHistory('/'),
  routes,
  scrollBehavior(_to, _from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    }
    return { top: 0 };
  },
});

export default router;

